<script src="/js/jquery/md5.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	var pg = App.auth.sysLogin.ui, failCt = 0;
	var frm = {
		type: pg.seek('type'),
		code: pg.seek('code'),
		pwd: pg.seek('pwd'),
		vc: pg.seek('vc'),
		msg: pg.seek('msg')
	}
	function valid(p){
		var m = frm.msg.empty();
		if(!p.code){
			frm.code.next().html('账号不能为空').show();
			return false;
		}
		if(!p.pwd){
			frm.pwd.next().html('密码不能为空').show();
			return false;
		}
// 		var r1 = /^[A-Za-z0-9\d]+([-_\.\+]*[A-Za-z0-9\d])*@([a-z0-9\d][a-z0-9\d-]{0,61}[a-z0-9\d]\.)+[a-z\d]{2,6}$/;
// 		var r2 = /^(13[0-9]|14[0-9]|15[0-9]|170|177|18[0-9])\d{8}$/;
// 		if(!r1.test(p.code) && !r2.test(p.code)){
// 			frm.code.next().html('只能是手机或邮箱').show();
// 			return false;
// 		}
		if (failCt > 2) {
			if (!p.vc) {
				m.text('请填写验证码').show();
				return false;
			}
		}
		return true;
	}
	var okBtn = pg.seek('ok').click(function(){
		var o = {
			type: frm.type.val(),
			code: frm.code.val(),
			pwd: frm.pwd.val(),
			vc: frm.vc.val()
		}
		if (!valid(o))
			return;
		//
		var w = mac.wait('Loading...');
		$.post(App.auth.ctx + '/sys/user/login.do', {
			code: o.code,
			password: $.md5(o.pwd),
			verifyCode: o.vc,
			r: Math.random()
		}, function(rs){
			var ro = mac.eval(rs);
			if (ro.success) {
				if (pg.callback) {
					pg.callback(ro.data, w);
				}
				if (pg.close) {
					pg.close();
				}
				pg.hide();
				//window.location.href = App.auth.ctx + '/index.html';
			} else {
				w.close();
				failCt = ro.params[0];
				if (failCt > 2) {
					pg.find('.verify').show();
					pg.seek('renew').click();
				}
				frm.msg.html('用户密码错误');
			}
		});
		return false;
	});
	frm.pwd.keydown(function(e){
		if (e.keyCode == 13) {
			okBtn.click();
		}
	});
	pg.seek('renew').click(function(){
		$('#vcImg').attr('src', App.auth.ctx + '/sys/power/verifyCode.do?r=' + Math.random());
		return false;
	});

	function adjust(){
		var de = document.documentElement
			, ch = de.clientHeight, cw = de.clientWidth
			, fm = pg.children('.form')
			, dw = fm.width() + 64
			, w = ch * 780 / 850 + dw;
		pg.css({
			height: ch,
			width: cw,
			top: 0,
			left: 0
		});
		pg.children('.cover').css({
			height: ch,
			width: w - dw,
			'margin-left': (cw - w) / 2
		});
		fm.css('margin-top', (ch - fm.height())/2);
	}
	$(window).resize(adjust);
	adjust();
});
</script>
<div class="cover">
</div>
<div class="form">
	<div class="logo"></div>
	<h2>用户登录</h2>
	<input type="hidden" name="type" />
	<div class="item">
		<div class="square">
			<span class="icon icon-user"></span>
		</div>
		<input type="text" name="code" placeholder="用户名" />
		<div class="clear"></div>
	</div>
	<div class="item">
		<div class="square">
			<span class="icon icon-password"></span>
		</div>
		<input type="password" name="pwd" placeholder="密码" />
		<div class="clear"></div>
	</div>
	<div class="item verify hidden">
<!-- 		<div class="label">验证码</div> -->
		<input name="vc" type="text" placeholder="请输入验证码"
			class="verifyCode empty">
		<div class="fl">
			<img id="vcImg" src="" align="middle" />
		</div>
		<button name="renew">换一张</button>
		<div class="clear"></div>
	</div>
	<div class="forgot">
		<a href="./user/retrieve.html">忘记密码</a>
	</div>
	<div class="msg" name="msg"></div>
	<div class="bottom">
		<button name="ok">登录</button>
	</div>
</div>